home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Alpha ƒ / Tcl / UserCode / Text Filters / CC to BibTeX next >
Text File  |  1994-03-14  |  5KB  |  145 lines

  1. #!/usr/local/bin/perl
  2. #
  3. #  Translate Current Contents citations into BibTeX article records
  4. #
  5. #  Select full-paragraph records and multi-line search
  6. $/ = "" ;
  7. $* = 1 ;
  8.  
  9. #  for each citation ...
  10. Record:
  11. while (<>) {
  12.    @ccLines = split("\n") ;
  13.    shift(@ccLines) if (! $ccLines[0]) ;
  14.    next Record if $ccLines[0] !~ /^\s*\d+\.\s+/ ;
  15.    
  16.    $authors = shift(@ccLines) ;
  17.    $authors =~ s/(^\s*\d+\.\s+)// ;
  18.    $ind = length($1) ;
  19.    @auths = split("[;\.]",$authors) ;
  20.    foreach (@auths) {
  21.       @wds = split(" ") ;
  22.       $init = pop(@wds) ;
  23.       $init =~ s/([A-Z])/$1. /g ;
  24.       $init =~ s/ +$// ;
  25.       $body = join(" ",@wds) ; 
  26.       $body =~ s/\b([A-Z])([A-Z]*)\b/\u$1\L$2/g ;
  27.       $_ = join(" ",($init,$body,"and")) ;
  28.    }
  29.    $authors = join(" ",@auths) ;
  30.    $authors =~ s/others and/et al./ ;
  31.    $authors =~ s/ and *$// ;
  32. #   print STDOUT $authors,"\n" ;
  33.    
  34.    $title = shift(@ccLines) ;
  35.    while ($ccLines[0] =~ /^ {$ind}\w/) {
  36.       $title = join(" ",($title,shift(@ccLines)))  ;
  37.    }
  38.    $title =~ s/^ +// ;
  39.    $title =~ s/  +/ /g ;
  40.    $title =~ s/\b(\w)(\w+)\b/\u$1\L$2/g ;
  41.    $title =~ s/\b(And|Or|Of|The|In|A|For)\b/\L$1/g ;
  42.    $title =~ s/^(\w)(\w*)\b/\u$1\L$2/g ;
  43.    $title =~ s/([:;\-\.] *)(\w)(\w*)\b/$1\u$2\L$3/g ;
  44. #   print STDOUT $title,"\n" ;
  45.    
  46.    $cite = shift(@ccLines) ;
  47.    if ($cite =~ /Pub/) { $cite = shift(@ccLines) ; } ;
  48.    while ($ccLines[0] =~ /^ {$ind}\w/) {
  49.       $cite = join(" ",($cite,shift(@ccLines)))  ;
  50.    }
  51.    $cite =~ s/^ +// ;
  52.    $cite =~ s/  +/ /g ;
  53.    ($journal,$when,$where) = split("\s*[,\.]\s*",$cite) ;
  54.  
  55.    $journal =~ s/^ *// ;
  56.    $journal =~ s/\b(\w)(\w+)\b/\u$1\L$2/g ;
  57.  
  58. #  Abbreviate journal title following standard conventions
  59.    $journal =~ s/\s*\b(And|Or|Of|The|In|For)\b//g ;
  60.    $journal =~ s/-.*// ;
  61.    $journal =~ s/Journal\b/J./ ;
  62.    $journal =~ s/Letters\b/Lett./ ;
  63.    $journal =~ s/Review\w*/Rev./ ;
  64.    $journal =~ s/Report\w*/Rep./ ;
  65.    $journal =~ s/Proceed\w*/Proc./ ;
  66.    $journal =~ s/Annual\w*/Annu./ ;
  67.    $journal =~ s/Account\w*/Acc./ ;
  68.    $journal =~ s/Advance\w*/Adv./ ;
  69.    $journal =~ s/Annal\w*/Ann./ ;
  70.    $journal =~ s/Bulletin\b/Bull./ ;
  71.    $journal =~ s/Transaction\w*/Trans./ ;
  72.    $journal =~ s/Discussion\w*/Discuss./ ;
  73.    $journal =~ s/Communi\w*/Comm./ ;
  74.    $journal =~ s/Progress\w*/Prog./ ;
  75.    $journal =~ s/Research\b/Res./ ;
  76.    $journal =~ s/Biolog\w*/Bio./ ;
  77.    $journal =~ s/Biophysic\w*/Biophys./ ;
  78.    $journal =~ s/Biochemi\w*/Biochem./ ;
  79.    $journal =~ s/Biomolec\w*/Biomol./ ;
  80.    $journal =~ s/Comput\w*/Comp./ ;
  81.    $journal =~ s/Chemi\w*/Chem./ ;
  82.    $journal =~ s/Organic\b/Org./ ;
  83.    $journal =~ s/Inorganic\b/Inorg./ ;
  84.    $journal =~ s/Mathem\w*/Math./ ;
  85.    $journal =~ s/Engineer\w*/Eng./ ;
  86.    $journal =~ s/Statisti\w*/Stat./ ;
  87.    $journal =~ s/Surface\w*/Surf./ ;
  88.    $journal =~ s/Magnetic Resonance\b/Magn. Res./ ;
  89.    $journal =~ s/Struct\w*/Struc./ ;
  90.    $journal =~ s/Theor\w*/Theo./ ;
  91.    $journal =~ s/Physi\w*/Phys./ ;
  92.    $journal =~ s/Photochemi\w*/Photochem./ ;
  93.    $journal =~ s/Photobiologi\w*/Photobiol./ ;
  94.    $journal =~ s/Philosoph\w*/Phil./ ;
  95.    $journal =~ s/Optic\w*/Opt./ ;
  96.    $journal =~ s/Electronic\w*/Electron./ ;
  97.    $journal =~ s/Quantum\w*/Quant./ ;
  98.    $journal =~ s/Appli\w*/Appl./ ;
  99.    $journal =~ s/Modern\b/Mod./ ;
  100.    $journal =~ s/National\b/Natl./ ;
  101.    $journal =~ s/International\b/Int./ ;
  102.    $journal =~ s/Royal\b/R./ ;
  103.    $journal =~ s/Faraday\b/Faraday/ ;
  104.    $journal =~ s/Society\b/Soc./ ;
  105.    $journal =~ s/Academ\w*/Acad./ ;
  106.    $journal =~ s/American\b/Am./ ;
  107.    $journal =~ s/Sciences\b/Sci./ ;
  108.    $journal =~ s/United States America/U.S.A./ ;
  109.    $journal =~ s/\bIbm\b/IBM/ ;
  110.    $journal =~ s/\bIeee\b/IEEE/ ;
  111.  
  112. #  Abbreviation rules for foreign-language journals
  113.    $journal =~ s/\s*\b(Et|Und|Der|De|Fur)\b//g ;
  114.    $journal =~ s/Zeitschrift\w*/Z./ ;
  115.    $journal =~ s/Berichte\w*/Ber./ ;
  116.    $journal =~ s/Bunsen Gesellschaft\b/Bunsenges./ ;
  117.    $journal =~ s/Chimi\w*\b/Chim./ ;
  118.    $journal =~ s/Biochimi\w*\b/Biochim./ ;
  119.    $journal =~ s/Chinese\b/Chin./ ;
  120.    $journal =~ s/Japanese\b/Jap./ ;
  121.    $journal =~ s/Europhysi\w*/Europhys./ ;
  122.  
  123. #  Extract year, month and day
  124.    ($year,$month,$day) = split(' ',$when) ;
  125. #  Capitalize months   
  126.    $month =~ s/\b(\w)(\w+)\b/\u$1\L$2/g ;
  127.  
  128.    if ($where =~ /V(\d+)/ ) { $volume = $1 ; } ;
  129.    if ($where =~ /N(\d+)/ ) { $issue = $1 ; } ;
  130.    if ($where =~ /:(\d+)/ ) { $pages = $1 ; } ;
  131.    
  132. #  generate output record in BibTeX form
  133.     print STDOUT '@article{,',"\n" ;
  134.     print STDOUT "\tauthor = \t\{$authors\},\n" ;
  135.     print STDOUT "\ttitle = \t\{$title\},\n" ;
  136.     print STDOUT "\tjournal = \t\{$journal\},\n" ;
  137.     print STDOUT "\tvolume = \t$volume,\n" ;
  138.     print STDOUT "\tpages =  \t$pages,\n" ;
  139.     print STDOUT "\tyear =   \t$year,\n" ;
  140.     print STDOUT "\tnote =   \t\{\},\n" ;
  141.     print STDOUT "\}\n" ;
  142.     
  143. }
  144.  
  145.